package Bi_Tree.bi_search_tree;

import Bi_Tree.TreeNode;

import java.util.*;

public class lc98 {

    //验证二叉搜索树
    public boolean isValidBST(TreeNode root) {
        Stack<TreeNode> stack=new Stack<>();
        List<Integer> list=new ArrayList<>();
        if(root.left==null&&root.right==null&&root!=null){
            return true;
        }
        TreeNode node=root;
        while(node!=null||!stack.isEmpty()){
            if(node!=null){
                stack.push(node);
                node=node.left;
            }else{
                node=stack.pop();
                list.add(node.val);
                node=node.right;
            }
        }
        for(int i=0;i<list.size();++i){
            System.out.println(list.get(i));
        }
        for(int i=0;i<list.size()-1;++i){
            if(list.get(i)>=list.get(i+1)){
                return false;
            }
        }

        return true;

    }
}
